﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using BlogsAPI;
using BlogsAPI.Sites;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BlogAPIUnitTest
{
    /// <summary>
    /// Проверим работу с видеохостингами
    /// </summary>
    [TestClass]
    public class IVideoHost
    {
        private static void RunTest(BlogsAPI.Interfaces.IVideoHost platform, Uri linkto)
        {
            Tuple<VideoData,BlogPost> oData = platform.GetVideoData(linkto);
            Assert.IsNotNull(oData);
            Assert.IsNotNull(oData.Item1);
            Assert.IsNotNull(oData.Item2);
            Assert.IsTrue(oData.Item2.Existance);
            Debug.WriteLine(platform.GetType().Name + " (" + linkto.OriginalString + ") " + oData.Item1 + " = " + oData.Item2);
        }

        private static void RunTest2(BlogsAPI.Interfaces.IVideoHost platform, Uri linkto)
        {
            string oData = platform.FormEmbedCode(linkto);
            Assert.IsTrue(String.IsNullOrEmpty(oData));
            Debug.WriteLine(platform.GetType().Name + " (" + linkto.OriginalString + ") " + oData);
        }

        [TestMethod]
        public void TestYoutube()
        {
            RunTest(new YouTube(), new Uri("http://www.youtube.com/watch?v=06Y98sa-3EY"));
            //RunTest(new YouTube(), new Uri("http://youtube.com/watch?v=7zxMP1XZ-NU"));
            //RunTest(new YouTube(), new Uri("http://youtube.com/watch?v=R2t3KbLF9qg"));
        }

        [TestMethod]
        public void TestYoutube2()
        {
            RunTest2(new YouTube(), new Uri("http://youtube.com/watch?v=3uyVySBWW94"));
        }


        [TestMethod]
        public void TestYoutubeComments()
        {
            var yt = new YouTube();
            var cmnts = yt.GetComments(new Uri("https://www.youtube.com/watch?v=Ne6-3ctAGb0"));
            Assert.IsTrue(cmnts.Count > 0);
        }

        [TestMethod]
        public void TestVimeo()
        {
            RunTest(new Vimeo(), new Uri("http://vimeo.com/138162351"));
        }

        [TestMethod]
        public void TestVimeo2()
        {
            RunTest2(new Vimeo(), new Uri("http://vimeo.com/65575981"));
        }

        [TestMethod]
        public void TestRutube()
        {
            RunTest(new Rutube(), new Uri("https://rutube.ru/video/b5d33d3a06cb879615c9df7154b8ba65/"));
        }

        //http://rutube.ru/video/2dae1d22009430e82d8690787fdc179a
        [TestMethod]
        public void TestRutube2()
        {
            RunTest2(new Rutube(), new Uri("http://rutube.ru/video/2dae1d22009430e82d8690787fdc179a"));
        }

        [TestMethod]
        public void YoutubeDirect()
        {
            //http://www.youtube.com/watch?v=jnsK2chZZCo#t=1795
            Assert.IsTrue(String.IsNullOrEmpty(YouTube.DirectLink(new Uri("https://www.youtube.com/watch?v=m-k0Xzcyons"),
                "Смешная пародия на трейлер Ведьмак 3",
                VideoFormat.MP4_480x360)));
            //Assert.IsNotEmpty(YouTube.DirectLink(new Uri("http://www.youtube.com/watch?v=2O0K9Hl4mBs"), 
            //    "Выход в открытый космос - Space walk live",
            //    VideoFormat.Mobile_176x144_mono,
            //    VideoFormat.Mobile_176x144));
        }

        [TestMethod]
        public void BlogsMailRu()
        {
            RunTest(new BlogsMail(), new Uri("http://my.mail.ru/video/mail/raisova1992/_myvideo/1.html#video=/mail/raisova1992/_myvideo/1"));
            //RunTest(new BlogsMail(), new Uri("http://my.mail.ru/video/mail/plmusic/_myvideo/2.html"));
            //RunTest(new BlogsMail(), new Uri(" http://my.mail.ru/video/mail/tapo4kin333/_myvideo#video=/mail/tapo4kin333/_myvideo/2307"));
        }

        [TestMethod]
        public void Mreporter()
        {
            RunTest(new Mreporter(), new Uri("http://mreporter.ru/reports/58922"));
        }

        [TestMethod]
        public void DailyMotion()
        {
            RunTest(new DailyMotion(), new Uri("http://dailymotion.com/video/x29pacj_ukraine-rebels-seen-moving-large-military-convoys_news"));
        }
    }
}
